package com.example.lx6_2.adapter

import android.widget.CheckBox
import androidx.databinding.DataBindingUtil
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.base.entity.OrderEntity
import com.example.base.entity.OrderEntityItem
import com.example.lx6_2.R
import com.example.lx6_2.databinding.ItemOrderBinding

class OrderAdapter : BaseQuickAdapter<OrderEntityItem, BaseViewHolder>(R.layout.item_order) {
    override fun onItemViewHolderCreated(viewHolder: BaseViewHolder, viewType: Int) {
        super.onItemViewHolderCreated(viewHolder, viewType)
        DataBindingUtil.bind<ItemOrderBinding>(viewHolder.itemView)
    }

    override fun convert(helper: BaseViewHolder, item: OrderEntityItem) {
        val binding = DataBindingUtil.getBinding<ItemOrderBinding>(helper.itemView)
        binding?.order = item
        val view = helper.getView<CheckBox>(R.id.cb)
        view.isChecked = item.check
        view.setOnClickListener {
            item.check = view.isChecked
        }
    }
}